<?php
class TestController extends Zend_Controller_Action {

    private static $memcache;
    private static $query_cache;

    public function __construct(\Zend_Controller_Request_Abstract $request, \Zend_Controller_Response_Abstract $response, array $invokeArgs = array()) {
        parent::__construct($request, $response, $invokeArgs);
        
        $this->_helper->viewRenderer->setNoRender(true);
        $frontendoptions = array(
            'lifetime' => 60 * 1, // 15minutes
            'automatic_serialization' => true
        );
        $backendoptions = array(
            'cache_dir' => CACHED_PATH,
            'file_name_prefix' => 'zend_cache_query_cabMeme',
            'hashed_directory_level' => 2
        );


        self::$query_cache = Zend_Cache::factory('Core', 'File', $frontendoptions, $backendoptions);
    }
    
    public function indexAction(){
         $this->_helper->viewRenderer->setNoRender(true);
    }
    
    
    public function clearAction(){        
        self::$query_cache->clean(Zend_Cache::CLEANING_MODE_ALL);
        echo "clear";
    }

    public function testfileAction() {
        $this->_helper->viewRenderer->setNoRender(true);
        if (!$result = self::$query_cache->load("test")) {
             echo 'get data cached to file';
             $data = array(
                 'thanh' => 'thanh'
             );
             
             self::$query_cache->save($data, "test");
         } else {
             echo 'from cached file';
         }
             
    }
}
?>